package com.cwt_taxi_xa.util;

import com.cwt_taxi_xa.MainApplication;
import com.cwt_taxi_xa.constants.MyStatus;
import com.cwt_taxi_xa.constants.SPConstants;
import com.cwt_taxi_xa.protocol.MCUUtil;

public class IPCallUtil {
    static String TAG = "IPCallUtil";
    //最后的音量
    public static int lastvic = 6;
    public static boolean ipvic = false;

    public synchronized static void speakIP() {
        //if (MyStatus.vichl != 4) {
            MyStatus.lastvichl = MyStatus.vichl;
            MCUUtil.selecterVic(4);
       // }
        //if (!ipvic) {
            ipvic = true;
            lastvic = SPUtils.getParamInteger(SPConstants.SPK_vol, SPConstants.SPV_vol);
            AppLog.d(TAG, "speakIP volume:" + lastvic);
            MCUUtil.changeVolume(1,20);
            MCUUtil.changeVolume(7,20);
            MCUUtil.changeVolume(2,20);
            //MCUUtil.setvol(SPUtils.getParamInteger(SPConstants.SPK_vol, SPConstants.SPV_vol_voice), "IP通话");
            //MCUUtil.setvol(20, "IP通话");
        //}

        try {
            AppLog.d(TAG,"runnable:IP通话超时启动");
            MainApplication.handler.postDelayed(runnable,5*60*1000);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public synchronized static void speakIPEnd(){
        if(ipvic){
            ipvic = false;
            MCUUtil.selecterVic(MyStatus.lastvichl);
            MCUUtil.setvol(lastvic, "IP通话结束恢复音量");
            AppLog.d(TAG,"runnable:IP通话超时结束");
        }
        try {
            MainApplication.handler.removeCallbacks(runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static Runnable runnable = new Runnable() {
        @Override
        public void run() {
            speakIPEnd();
        }
    };
}
